<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* 
    Object.defineProperty();
    */
   var obj = {
     a: 10
   }
   var a = 100;
   Object.defineProperty(obj,'a', {
     get(){
       /* 
       拦截器 getter 
       拦截了 obj对象a属性的获取操作
       */
      return a;
     },
     set(newVal){
       /* 
       setter 拦截 obj a属性设置的操作
       */
      console.log('setter触发了', newVal);
      a = newVal;
     }
   })
   console.log(obj.a);
   obj.a = 400;
   console.log(obj.a);
  </script>
</body>
</html>